﻿using Autofac;
using System.Reflection;

namespace Q.M.Sell.Read.API.MyModule
{
   
    public class FinanceModule:Autofac.Module
    {
        /// <summary>
        /// 重写Load方法
        /// </summary>
        protected override void Load(ContainerBuilder builder)
        {
            //反射加工厂设计模式完成的
            //业务逻辑
            //通过反射的方式加载类库（程序集）
            //Assembly反射的类库
            var Repository = Assembly.Load("Q.M.Finance.Infrastruecure");
            var Services = Assembly.Load("Q.M.Finance.Application");
            //将程序集注入到AutoFac当中
            //AsImplementedInterfaces()比如现在是一个实体类，它会自动找到他的接口来实现
            builder.RegisterAssemblyTypes(Repository)
            .Where(x => x.Name.EndsWith("Repository")).AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(Services)
            .Where(x => x.Name.EndsWith("Services")).AsImplementedInterfaces();
            base.Load(builder);
        }
    }
}
